# 导包
import requests
import config


# 创建接口类（模块）
class LoginAPI:
    # 初始化
    def __init__(self):
        self.url_code = config.BASE_URL + "/api/captchaImage"
        self.url_login = config.BASE_URL + "/api/login"

    # 获取验证码接口
    def get_verify_code(self):
        return requests.get(url=self.url_code)

    # 登录接口
    def login(self, test_data):
        return requests.post(url=self.url_login, json=test_data)


if __name__ == '__main__':
    # 实例化接口类的对象
    login_api = LoginAPI()
    # 获取图片验证码
    response = login_api.get_verify_code()
    print(response.status_code)
    print(response.json())
    # 提取获取图片验证码返回的uuid参数值
    uuid = response.json().get("uuid")
    # 登录成功
    test_data = {
        "username": "admin",
        "password": "admin123",
        "code": "2",
        "uuid": uuid
    }
    response = login_api.login(test_data=test_data)
    print(response.status_code)
    print(response.json())